//##include('../block/lazyload.js');
//##include('../block/doT.js');
$(document).ready(function(){
    var index=location.href.lastIndexOf("/");
    var str=location.href.substr(index+1);
    var id=str.split("_")[1];
    var p=1;

    var $authorlist = $('.content-item').find('.lists');
    function ajaxRequest(){
       $.ajax({
           type: 'GET',
           url: '/author/author_apis/authorlist?id='+ id+"&p="+ p,
           dataType: 'json',
           success: function(data){
               var len = data.list.length;

               if(len > 0){
                   var temID = $authorlist.attr('temId');
                   var tmpl = $("#"+temID).html();
                   var doTtmpl = doT.template(tmpl);
                   $authorlist.append(doTtmpl(data));
                   $(".lazy").lazyload({
                       effect : "fadeIn"
                   });
               }else{
                   if(p!=1){
                       $("#nomore").addClass("block");
                   }
               }
           },
           error: function(){
               console.log('Ajax error!');
           }
       });
    }
    ajaxRequest();

    $(window).on('scroll',function(){
        if($(document).height() <= document.documentElement.clientHeight + $(window).scrollTop()){
            p++;
            ajaxRequest();
        }
    })
});
